<?if (isset($currentCategory)):?>
	<h1>Current category: <?=Html::chars($currentCategory['name'])?></h1>
<?else:?>
	<h1><?=(isset($moduleSettings['title']) ? $moduleSettings['title'] : ucfirst($section))?></h1>
	<? if (isset($moduleSettings['description'])): ?>
		<p><?=$moduleSettings['description']?></p>
	<? endif; ?>
<?endif?>
<table class="<?=((isset($moduleSettings['levels']) ? $moduleSettings['levels'] : true) ? 'w100' : 'w50')?>">
	<tr>
		<? if ((isset($moduleSettings['levels']) ? $moduleSettings['levels'] : true)): ?>
			<td class="w50 top paddingRight10" style="border-right: solid 1px #eee;">
				<?if (isset($currentCategory)):?>
					<p>
						<img src="/images/icons/smallFolderUp.png" width="32" height="32" alt="" class="middle"/>
						<?=Html::anchor(Request::$controller . ($currentCategory['parentId'] != 0 ? 'browse/' . $section . '/' . $currentCategory['parentId'] . '/' : 'browse/' . $section . '/'), '&uarr; Up category')?>
					</p>
				<?endif?>
				<hr />
				<?if (isset($categories) ? count($categories) : false):?>
					<ul class="list sortable">
					<?foreach($categories as $category):?>
						<?
							$name = isset($moduleSettings['categories']['title']) ? $category[$moduleSettings['categories']['title']] : $category['name'];
							$name = strip_tags($name);
							$name = strlen($name) > 30 ? substr($name, 0, 25) . '...' : $name;
						?>
						<li id="categories_<?=$category['id']?>">
							<table class="w100">
								<tr>
									<? if ($itemData['permissions']['categories']['sorting']): ?>
										<td class="center" style="width: 30px;">
											<span class="sortable-handler"><img src="/images/icons/sort.png" class="middle" /></span>
										</td>
									<? endif; ?>
									<td>
										<img src="/images/icons/smallFolder.png" width="32" height="32" alt="" class="middle"/>
										<?=Html::anchor(Request::$controller . 'browse/' . $section . '/' . $category['id'] . '/', Html::chars($name))?>
									</td>
									<td style="width: 50px;" class="right">
										<? if ($itemData['permissions']['categories']['edit']): ?>
											<?=Html::anchor(Request::$controller . 'item/' . $section . '/' . $category['id'] . '/', '<img src="/images/icons/edit.png" width="16" height="16" alt="Edit"/>')?>
										<? endif; ?>
										<? if ($itemData['permissions']['categories']['delete']): ?>
											&nbsp;
											<?=Html::anchor(Request::$controller . 'removeCategory/' . $section . '/' . $category['id'] . '/', '<img src="/images/icons/remove.png" width="16" height="16" alt="Delete folder"/>', array('onclick' => 'javascript:return confirm(CONFIRMATION_REMOVE)'))?>
										<? endif; ?>
									</td>
								</tr>
							</table>
						</li>
					<?endforeach?>
					</ul>
					<hr />
				<?endif?>
	<!-- Add new category !-->
				<? if ($itemData['permissions']['categories']['add']): ?>
					<p>
						<img src="/images/icons/smallFolderAdd.png" width="32" height="32" alt="" class="middle"/>
						<?=Html::anchor(Request::$controller . 'addCategory/' . $section . '/' . (isset($parentId) ?  $parentId . '/' : ''), 'Add category')?>
					</p>
				<? endif; ?>
			</td>
		<? endif; ?>
		<td class="w50 top paddingLeft10">
			<?if (isset($items) ? count($items) : false):?>
				<hr />
				<ul class="list sortable">
				<?foreach($items as $item):?>
					<?
						$name = isset($moduleSettings['items']['title']) ? $item[$moduleSettings['items']['title']] : $item['name'];
						$name = strip_tags($name);
						$name = strlen($name) > 30 ? substr($name, 0, 25) . '...' : $name;
					?>
					<li id="items_<?=$item['id']?>">
							<table class="w100">
								<tr>
									<? if ($itemData['permissions']['items']['sorting']): ?>
										<td class="center" style="width: 30px;">
											<span class="sortable-handler"><img src="/images/icons/sort.png" class="middle"/></span>
										</td>
									<?endif?>
									<td>
										<?=Html::chars($name)?>
									</td>
									<td style="width: 50px;" class="right">
										<?=Html::anchor(Request::$controller . 'item/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/edit.png" width="16" height="16" alt="Edit"/>')?>
										<? if ($itemData['permissions']['items']['delete']): ?>
											&nbsp;
											<?=Html::anchor(Request::$controller . 'removeItem/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/remove.png" width="16" height="16" alt="Delete folder"/>', array('onclick' => 'javascript:return confirm(CONFIRMATION_REMOVE)'))?>
										<?endif?>
									</td>
								</tr>
							</table>
						</li>
				<?endforeach?>
				</ul>
				<hr />
			<?endif?>
			<? if ($itemData['permissions']['items']['add']): ?>
				<?=Html::anchor(Request::$controller . 'addItem/' . $section . '/' . (isset($parentId) ?  $parentId . '/' : ''), 'Add item')?>
			<?endif?>
		</td>
	</tr>
</table>